import UpswarnData from "../config/UpswarnData";

export default class WarnLogVo {

    public id:string;
    /**
     * 设备id
     */
    public sebeiId:string;

    /**
     * 告警来源，0 ping，1 snmp, 2 modbus , rtsp
     */
    public sourceTarget:number;

    /**
     * 告警类型，0一般事件，1橙色事件，2红色告警
     */
    public  type:number;
    /**
     * 内容
     */
    public content:string;
    /**
     * 是否确认
     */
    public isverify:boolean;
    /**
     * 是否已联系，告警联系人
     */
    public iscall:boolean;

    public creationDateTime:string;

    public sebeikey:string;

    public sebeiname:string;

    public errorContent:string;

    public floorName:string;

    
    public sourceTargetStr = "";

    public typeStr = "";

    public creationDateTimeStr = "";

    public floorNameStr = "";


    public errorContentStr = "";



    constructor(obj:any){
        for (const key in obj) {
            this[key] = obj[key];
        }
        this.id = obj.id+"";
        this.sebeiId = obj.sebeiId+"";

        this.creationDateTimeStr = this.formatTime(this.creationDateTime);

        this.floorNameStr = this.floorName+"F";

        if(this.errorContent == "pingFail")
        {
            this.errorContentStr = "设备不在线";
        }
        else if(this.errorContent == "reviceRTUfail")
        {
            this.errorContentStr = "接收UPS数据超时";
        }
        let upsWarnInfo = UpswarnData.getInfo(this.errorContent);
        if(upsWarnInfo)
        {
            this.errorContentStr = upsWarnInfo;
        }
    }

    private  formatTime(time, format = 'YYYY-MM-DD hh:mm:ss') {
        if (!time) return '';
        var datetime = new Date(time);
        var o = {
            'Y+': datetime.getFullYear(),
            "M+": datetime.getMonth() + 1,
            "D+": datetime.getDate(),
            "h+": datetime.getHours(),
            "m+": datetime.getMinutes(),
            "s+": datetime.getSeconds(),
            "q+": Math.floor((datetime.getMonth() + 3) / 3),
            "S": datetime.getMilliseconds()
        };
        if (/(Y+)/.test(format)) format = format.replace(RegExp.$1, (datetime.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            }
        return format;
    }


}